//
// *  $Id: TestFreePhysicalRowIdPage.java,v 1.3 2003/09/21 15:49:02 boisvert Exp $
// *
// *  Unit tests for FreePhysicalRowIdPage class
// *
// *  Simple db toolkit
// *  Copyright (C) 1999, 2000 Cees de Groot <cg@cdegroot.com>
// *
// *  This library is free software; you can redistribute it and/or
// *  modify it under the terms of the GNU Library General Public License
// *  as published by the Free Software Foundation; either version 2
// *  of the License, or (at your option) any later version.
// *
// *  This library is distributed in the hope that it will be useful,
// *  but WITHOUT ANY WARRANTY; without even the implied warranty of
// *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// *  Library General Public License for more details.
// *
// *  You should have received a copy of the GNU Library General Public License
// *  along with this library; if not, write to the Free Software Foundation,
// *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
// 

//*************************************************************************
//**  Included in JDMB 1.0 port to SharpDBM;  11/2013 Cyrus Neah cneah@codingreal.com
//**  SharpDBM is an independent reimplementation of the JDBM 1.0 software library  
//*************************************************************************

using SharpDBM;
using SharpDBM.recman;
using SharpDBM.helper;
using SharpDBM.btree;
using NUnit.Framework;



namespace SharpDBM.Test

.recman
{

 
	 

///
// *  This class contains all Unit tests for {@link FreePhysicalRowIdPage}.
// 
	[TestFixture]
    public class TestFreePhysicalRowIdPage 
	{

		


//    *
//     *  Test constructor - create a page
//     
 
//
		[Test]
 public virtual void testCtor()
		{
	  sbyte[] data = new sbyte[RecordFile.BLOCK_SIZE];
	  BlockIo test = new BlockIo(0, data);
	  new PageHeader(test, Magic.FREEPHYSIDS_PAGE);
	  FreePhysicalRowIdPage page = new FreePhysicalRowIdPage(test);
		}

//    *
//     *  Test basics
//     
 
//
		[Test]
 public virtual void testBasics()
		{
	  sbyte[] data = new sbyte[RecordFile.BLOCK_SIZE];
	  BlockIo test = new BlockIo(0, data);
	  new PageHeader(test, Magic.FREEPHYSIDS_PAGE);
	  FreePhysicalRowIdPage page = new FreePhysicalRowIdPage(test);

  // we have a completely empty page.
      NUnit.Framework.Assert.AreEqual(0, page.getCount(), "zero count");

  // three allocs
	  FreePhysicalRowId id = page.alloc(0);
	  id = page.alloc(1);
	  id = page.alloc(2);
      NUnit.Framework.Assert.AreEqual(3, page.getCount(), "three count");

  // setup last id (2)
	  id.setBlock(1);
	  id.setOffset((short) 2);
	  id.setSize(3);

  // two frees
	  page.free(0);
	  page.free(1);
      NUnit.Framework.Assert.AreEqual(1, page.getCount(), "one left count");
      NUnit.Framework.Assert.IsTrue(page.isFree(0), "isfree 0");
      NUnit.Framework.Assert.IsTrue(page.isFree(1), "isfree 1");
      NUnit.Framework.Assert.IsTrue(page.isAllocated(2), "isalloc 2");

  // now, create a new page over the data and check whether
  // it's all the same.
	  page = new FreePhysicalRowIdPage(test);

      NUnit.Framework.Assert.AreEqual(1, page.getCount(), "2: one left count");
      NUnit.Framework.Assert.IsTrue(page.isFree(0), "2: isfree 0");
      NUnit.Framework.Assert.IsTrue(page.isFree(1), "2: isfree 1");
      NUnit.Framework.Assert.IsTrue(page.isAllocated(2), "2: isalloc 2");

	  id = page.get(2);
      NUnit.Framework.Assert.AreEqual(1, id.getBlock(), "block");
      NUnit.Framework.Assert.AreEqual(2, id.getOffset(), "offset");
      NUnit.Framework.Assert.AreEqual(3, id.getSize(), "size");

		}


//    *
//     *  Runs all tests in this class
//     
		static void Main(string[] args)
		{
	  // junit.textui.TestRunner.run(new TestSuite(typeof(TestFreePhysicalRowIdPage)));
		}
	}

}